package com.pet.server.ext.action.square;


import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetAdopt;
import com.pet.server.ext.data.PetAdoptItem;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Adoptremove extends ActionBase{

	public Integer adopt_id;
	public Adoptremove(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		adopt_id = NumberUtil.getInteger(params.getFieldValue("adopt_id"));
		if(StringUtil.isEmpty(adopt_id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		PetAdopt pa = userService.findAdoptById(adopt_id);
		if(null==pa){
            throw ApiError.Type.LOGIC_ERROR.toException("领养信息不存在!");			
		}
		if(!StringUtil.equals(user.user_id, pa.user_id)){
			throw ApiError.Type.LOGIC_ERROR.toException("非自有信息!");
		}
		
		userService.updateForRemove(adopt_id);
		Result result = new Result();
		result.put("massage", "删除成功!");
	    return result;
	}


}
